package oop.ex3.serverprotocol;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import oop.ex3.nameserver.NameServer;
import oop.ex3.sharedclasses.IPaddress;

/**
 * Handles GOODBYE Message.
 * handles a client's notification that it is going down -
 * to update the NameServer to remove all of the info about this client.
 * 
 * @author zablo
 *
 */
public class Goodbye extends ClientMessageHandler {

	@Override
	public boolean run(NameServer server, IPaddress sessionIP,
			DataInputStream clientInput, DataOutputStream clientOutput) {
		if (endsWithEnd(clientInput)==FAILURE){
			return FAILURE;
		}
		
		if (ServerMessageSender.done(clientOutput)==FAILURE){
			return FAILURE;
		}
		//TODO check about the done before removing
		server.removeClient(sessionIP);
		
		return SUCCESS;
	}

}
